const query = require("../db/mysql")
const { success, error } = require("../module/module")

class Vadio {
    //获取直播列表数据
    getVadio = async (ctx) => {
        let { pageNum, pageSize } = ctx.request.body
        let sql = `select * from vadio where 1=1 `
        let countSql = 'select count(id) as total from vadio '
        let total = await query(countSql)
        if (pageNum * 1) {
            sql += `limit ${(pageNum * 1 - 1) * pageSize * 1},${pageSize * 1} `
        }
        let data = await query(sql)
        ctx.body = {
            total: total[0].total,
            data,
            code: 1
        }
    }
    //筛选直播
    select = async (ctx) => {
        let { ongoing } = ctx.request.body
        let sql = `select * from vadio where 1=1 `
        if (ongoing) {
            sql += `and ongoing like "%${ongoing}%" `
        }
        let data = await query(sql)
        if (data.length) {
            ctx.body = success(data, '选择成功')
        } else {
            error('选择失败')
        }

    }

    //查找经纪人
    searchName = async (ctx) => {
        let { name } = ctx.request.body
        let sql = `select * from vadio where 1=1 `
        if (name) {
            sql += `and name like "%${name}%"`
        }
        let data = await query(sql)
        ctx.body = success(data, "查找成功")
    }
}

module.exports = new Vadio()